#! /usr/bin/python

import mathex

def main():
    for a in mathex.comb(range(0,10),4):
        l = [reduce(lambda x,y:x*10+y,k,0) for k in mathex.perm(a)]
        for b in mathex.comb(l,3):
            b.sort()
##             if b[1]-b[0] == b[2]-b[1] \
##                 and reduce(lambda x,y:x and mathex.isPrime(y),b,True):
##                  print b
##             if b[1]-b[0] == b[2]-b[1]:
##                 print b
##             if reduce(lambda x,y:x and mathex.isPrime(y),b,True):
##                 print b
            if b[1]-b[0] == b[2]-b[1] \
               and reduce(lambda x,y:x and y>1000, b, True) \
               and reduce(lambda x,y:x and mathex.isPrime(y),b,True):
                print b

def main1():
    for a in comb(range(0,10),4):
        l = [reduce(lambda x,y:x*10+y,k,0) for k in mathex.perm(a)]
        for b in mathex.comb(l,3):
            b.sort()
            if b[1] - b[0] and b[1]-b[0] == b[2]-b[1] \
               and reduce(lambda x,y:x and y>1000, b, True) \
               and reduce(lambda x,y:x and mathex.isPrime(y),b,True):
                print b

def comb(items, n=None):
    '''generate the combination of items allow repeat item
    items: a list from which we fetch elements
    n: the length of item we want, if omitted n is length of items
    
    example: comb([1,2,3],2) will generate
    [1, 2], [1, 3], [2, 3]'''
    if n is None:
        n = len(items)    
    if n == 0:
        yield []
    else:
        for item in items:
            for a in comb(items,n-1):
                yield [item] + a
            
if __name__ == '__main__':
    main1()

    
